package com.tegistuff.webos.run.debugger.infrastructure;

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;

/**
 * WebOSThreadHelper.java
 *
 * Thread helper functions.
 *
 * Copyright (C) 2012 Timo Tegtmeier.
 * All rights reserved.
 */
public class WebOSThreadHelper {

    public static void run(Runnable runnable) {
        Application app = ApplicationManager.getApplication();
        app.invokeLater(runnable);
    }

    public static void runAndWait(Runnable runnable) {
        Application app = ApplicationManager.getApplication();
        if(app.isDispatchThread()) {
            runnable.run();
        } else {
            app.invokeAndWait(runnable, ModalityState.any());
        }
    }
}
